#include "visioninstructionview.h"
#include "ui_visioninstructionview.h"
#include "../../programView/programview.h"

VisionInstructionView::VisionInstructionView(int styleId,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::VisionInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);

    buttonGroup=new QButtonGroup;
    buttonGroup->addButton(ui->radioButton_visionFlag,0);
    buttonGroup->addButton(ui->radioButton_trackFlag,1);
    ui->radioButton_visionFlag->setChecked(true);

}

void VisionInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

VisionInstructionView::~VisionInstructionView()
{
    delete ui;
}

void VisionInstructionView::getValue()
{
    if(buttonGroup->checkedId())
    {
        isVisionCommandFlag=0;
    }
    else
    {
        isVisionCommandFlag=1;
    }
    note = ui->note_lineEdit->text();

    int commandType;
    int index;
    if(isVisionCommandFlag)
    {

        commandType=ui->comboBox_visionCommandType->currentIndex();
        index=ui->comboBox_visionIndex->currentIndex();
        switch(commandType)
        {
        case 0:
        {
            instructionString = QString("RUNVISION[%1]; //%2")
                    .arg(index)
                    .arg(note);
            break;
        }
        case 1:
        {
            instructionString = QString("TRIGGERVISION[%1]; //%2")
                    .arg(index)
                    .arg(note);
            break;
        }
        case 2:
        {
            instructionString = QString("GETVISIONDATA[%1]; //%2")
                    .arg(index)
                    .arg(note);
            break;
        }
        case 3:
        {
            instructionString = QString("CLEARVISIONDATA[%1]; //%2")
                    .arg(index)
                    .arg(note);
            break;
        }
        }

    }
    else
    {
        commandType=ui->comboBox_trackCommandType->currentIndex();
        index=ui->comboBox_trackIndex->currentIndex();
        switch(commandType)
        {
        case 0:
        {
            instructionString = QString("TRACKSTART[%1]; //%2")
                    .arg(index)
                    .arg(note);
            break;
        }
        case 1:
        {
            instructionString = QString("TRACKEND[%1]; //%2")
                    .arg(index)
                    .arg(note);
            break;
        }
        case 2:
        {
            instructionString = QString("GETTRACKDATA[%1]; //%2")
                    .arg(index)
                    .arg(note);
            break;
        }

        }
    }





}

void VisionInstructionView::updateView()
{
    if(isVisionCommandFlag)
    {
        ui->radioButton_visionFlag->setChecked(true);

        ui->comboBox_visionCommandType->setCurrentIndex(visionCommandIndex);
        ui->comboBox_visionIndex->setCurrentIndex(visionIndex);
    }
    else
    {

        ui->radioButton_trackFlag->setChecked(true);

        ui->comboBox_trackCommandType->setCurrentIndex(beltCommandIndex);
        ui->comboBox_trackIndex->setCurrentIndex(beltIndex);
    }

    ui->note_lineEdit->setText(note);
}

void VisionInstructionView::on_save_Btn_clicked()
{
    //获取语句
    getValue();

    //发送 保存
    emit saveInstruction(instructionString);
}

void VisionInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
}

void VisionInstructionView::on_forward_Btn_clicked()
{
    this->close();//????
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

